package rabbitmq.migration;

import java.sql.Connection;

import org.springframework.amqp.core.AmqpAdmin;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.TopicExchange;

import com.googlecode.flyway.core.api.migration.jdbc.JdbcMigration;
import com.kedacom.springx.context.SpringContextHelper;

public class V1_0_1__Declare_Exchange implements JdbcMigration {

	private AmqpAdmin amqpAdmin;

	public V1_0_1__Declare_Exchange() {
		init();
	}

	protected void init() {
		amqpAdmin = SpringContextHelper.getBean(AmqpAdmin.class);
	}

	@Override
	public void migrate(Connection connection) throws Exception {
		Exchange exchange = new TopicExchange("topic.exchange");
		amqpAdmin.declareExchange(exchange);
	}

}
